<?php
define('TEMPL_TPL_ROOT_PATH',TEMPLATEPATH.'/library/tpl/');

/************************************
//FUNCTION NAME : templ_template_include
//ARGUMENTS : None
//RETURNS : Site page template file as per desing settings
***************************************/
add_filter('template_include','templ_template_include');
function templ_template_include($file)
{
	if(is_search() && strstr($file,'/search.php'))
	{
		$template = templ_get_search_tpl(); //search
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/search.php';
		}
	}
	elseif(is_tax())
	{
		$template = templ_get_taxonomy_tpl(); //taxonomy
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/archive.php';
		}
	}
	elseif(is_page() && strstr($file,'/page.php'))
	{
		$template = templ_get_page_tpl(); // pages
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/page.php';
		}
	}elseif(is_author())
	{
		$template = templ_get_author_tpl(); //author detail
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/author.php';
		}
	}
	elseif(is_archive() && strstr($file,'/archive.php'))
	{
		global $wp_query;
		$current_term = $wp_query->get_queried_object();
		if($current_term->taxonomy=='category')
		{
			$template = templ_get_archive_tpl(); // category listing
		}else
		{
			$template = templ_get_taxonomy_tpl(); //taxonomy
		}
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/archive.php';
		}
	}
	elseif(is_single() && strstr($file,'/single.php'))
	{
		global $wp_query;
		$current_term = $wp_query->get_queried_object();
		if($current_term->post_type=='post')
		{
			$template = templ_get_single_tpl();	 // single
		}else
		{
			$template = templ_get_custom_post_tpl(); //custom post
		}		
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/single.php';
		}
	}
	elseif(is_home() && strstr($file,'/index.php'))
	{
		$template = templ_get_index_tpl(); // index
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/index.php';
		}
	}
	elseif(is_404() && strstr($file,'/404.php'))
	{
		$template = templ_get_404_tpl(); // 404
		if(!file_exists($template))
		{
			$template = TEMPLATEPATH.'/404.php';
		}
	}
	else
	{
		$template = $file;
	}
	return apply_filters('templ_add_template_page_filter',$template);
}

/************************************
//FUNCTION NAME : templ_get_page_tpl
//ARGUMENTS : None
//RETURNS : Page page template file as per desing settings
***************************************/
function templ_get_page_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'pages/page_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'pages/page_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'pages/page_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'pages/page_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'pages/page_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'pages/page_3_col_left.php';
	}
		return $template;
}

/************************************
//FUNCTION NAME : templ_get_author_tpl
//ARGUMENTS : None
//RETURNS : Author page template file as per desing settings
***************************************/
function templ_get_author_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'author/author_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'author/author_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'author/author_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'author/author_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'author/author_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'author/author_3_col_left.php';
	}
	return $template;
}

/************************************
//FUNCTION NAME : templ_get_archive_tpl
//ARGUMENTS : None
//RETURNS : Archive page template file as per desing settings
***************************************/
function templ_get_archive_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'archive/archive_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'archive/archive_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'archive/archive_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'archive/archive_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'archive/archive_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'archive/archive_3_col_left.php';
	}
	return $template;
}

/************************************
//FUNCTION NAME : templ_get_taxonomy_tpl
//ARGUMENTS : None
//RETURNS : Taxonomy page template file as per desing settings
***************************************/
function templ_get_taxonomy_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'taxonomy/taxonomy_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'taxonomy/taxonomy_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'taxonomy/taxonomy_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'taxonomy/taxonomy_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'taxonomy/taxonomy_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'taxonomy/taxonomy_3_col_left.php';
	}
	return $template;
}

/************************************
//FUNCTION NAME : templ_get_single_tpl
//ARGUMENTS : None
//RETURNS : Single page template file as per desing settings
***************************************/
function templ_get_single_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'single/single_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'single/single_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'single/single_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'single/single_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'single/single_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'single/single_3_col_left.php';
	}
	return $template;
}

/************************************
//FUNCTION NAME : templ_get_single_tpl
//ARGUMENTS : None
//RETURNS : Single page template file as per desing settings
***************************************/
function templ_get_custom_post_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'custom_post/post_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'custom_post/post_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'custom_post/post_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'custom_post/post_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'custom_post/post_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'custom_post/post_3_col_left.php';
	}
	return $template;
}

/************************************
//FUNCTION NAME : templ_get_index_tpl
//ARGUMENTS : None
//RETURNS : Index page template file as per desing settings
***************************************/
function templ_get_index_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'index/index_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'index/index_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'index/index_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'index/index_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'index/index_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'index/index_3_col_left.php';
	}
	return $template;
}

/************************************
//FUNCTION NAME : templ_get_search_tpl
//ARGUMENTS : None
//RETURNS : Search page template file as per desing settings
***************************************/
function templ_get_search_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'search/search_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'search/search_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'search/search_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'search/search_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'search/search_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'search/search_3_col_left.php';
	}
	return $template;
}

/************************************
//FUNCTION NAME : templ_get_404_tpl
//ARGUMENTS : None
//RETURNS : 404 page template file as per desing settings
***************************************/
function templ_get_404_tpl()
{
	if(get_option('ptthemes_page_layout')=='Full Page')
	{
		$template = TEMPL_TPL_ROOT_PATH.'404/404_full.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'404/404_2_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 2 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'404/404_2_col_left.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Fixed')
	{
		$template = TEMPL_TPL_ROOT_PATH.'404/404_3_col_fixed.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Right Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'404/404_3_col_right.php';
	}elseif(get_option('ptthemes_page_layout')=='Page 3 column - Left Sidebar')
	{
		$template = TEMPL_TPL_ROOT_PATH.'404/404_3_col_left.php';
	}
	return $template;
}
?>